package com.ljf.code.domain.validator;

import com.ljf.code.dto.other.TextConversionTranslation;
import com.ljf.code.enums.TextConversionTypeEnum;
import com.ljf.common.domain.validator.NoDbBasisValidator;
import com.ljf.common.exception.ServiceException;
import com.ljf.common.utils.CollectionUtil;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 文本转换  业务校验
 *
 * @author LJF
 * @since 2024-06-18
 */
@Component
public class TextConversionValidator extends NoDbBasisValidator {

    /**
     * 转化接口  业务校验
     *
     * @param model
     * @throws ServiceException
     */
    public void checkTranslation(TextConversionTranslation model) throws ServiceException {
        if (CollectionUtil.isEmpty(model.getDataList())) {
            throw new ServiceException("转化校验异常:请输入转换内容");
        }
        boolean isExist = false;
        for (TextConversionTypeEnum value : TextConversionTypeEnum.values()) {
            if (Objects.equals(model.getCode(), value.getCode())) {
                isExist = true;
                break;
            }
        }
        if (!isExist) {
            throw new ServiceException("转化校验异常:异常处理代码");
        }
    }
}
